package com.Scheduled;



import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import java.time.LocalDateTime;

@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务:默认为单线程，开启多个任务时，任务的执行时机会受上一个任务执行时间的影响
@EnableSchedulerLock(defaultLockAtMostFor = "PT30S")
public class SchedulerLockTask {

     @Value("${server.port}")
     private  String port ;

    //@Scheduled(cron = "0/5 * * * * ?")
    @SchedulerLock(name = "configureTasksLock1",lockAtLeastFor = "20000",lockAtMostFor = "30000")
    public void configureTasksLock1() throws InterruptedException {
        System.err.println("configureTasksLock1执行静态定时任务时间: " + LocalDateTime.now()+"===线程名称"+Thread.currentThread().getName()+"端口=="+port);
        Thread.sleep(10000);
    }
    //@Scheduled(cron = "0/10 * * * * ?")
   // @SchedulerLock(name = "configureTasksLock2",lockAtLeastFor = "10000",lockAtMostFor = "20000")
    public void configureTasksLock2() {
        System.err.println("configureTasksLock2执行静态定时任务时间: " + LocalDateTime.now()+"===线程名称"+Thread.currentThread().getName()+"端口=="+port);
    }
}
